<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>Spring MVC Form Handling</title>
	</head>
	<body>
		<h2>Add User Data</h2>
		<form:form method="POST" action="saveUser" width="90%">
	   		<table >
			    <tr>
			        <td><form:label path="id">User ID:</form:label></td>
			        <td><form:input path="id" value="${user.id}" readonly="true"/></td>
			    </tr>
			    <tr>
			        <td><form:label path="username">User Name:</form:label></td>
			        <td><form:input path="username" value="${user.username}"/></td>
			    </tr>
			    <tr>
			        <td><form:label path="password">User Password:</form:label></td>
			        <td><form:input path="password" value="${user.password}"/></td>
			    </tr>
			    <tr>
			        <td><form:label path="age">User Age:</form:label></td>
			        <td><form:input path="age" value="${user.age}"/></td>
			    </tr>
			    <tr>
			        <td><form:label path="email">User Email:</form:label></td>
			        <td><form:input path="email" value="${user.email}"/></td>
			    </tr>
			    <tr>
			        <td><form:label path="address">User Address:</form:label></td>
                    <td><form:input path="address" value="${user.address}"/></td>
			    </tr>
			    
			    <tr>
			      <td colspan="2"><input type="submit" value="Submit"/></td>
		      </tr>
			</table> 
		</form:form>
		
  <c:if test="${!empty users}">
		<h2>List Users</h2>
	<table align="left" border="1" width="100%">
		<tr>
			<th>User ID</th>
			<th>User Name</th>
			<th>User Password</th>
			<th>User Email</th>
			<th>User Address</th>
			<th>Actions on Row</th>
		</tr>

		<c:forEach items="${users}" var="user">
			<tr>
				<td><c:out value="${user.id}"/></td>
				<td><c:out value="${user.username}"/></td>
				<td><c:out value="${user.password}"/></td>
				<td><c:out value="${user.email}"/></td>
				<td><c:out value="${user.address}"/></td>
				<td align="center"><a href="editUser?id=${user.id}">Edit</a> | <a href="deleteUser?id=${user.id}">Delete</a></td>
			</tr>
		</c:forEach>
	</table>
</c:if>
	</body>
</html>